tempPath = Dir.pwd
require "#{tempPath}/xmlParser.rb"

# TODO: need to have a recursive function to create a tag tree
# TODO: create mechanism to recieve an xml string or an xml file name


class XMLTagTreeConstants
  OPENFILE = 0
  USESTRING = 1
end


class XMLTagTree

  def initialize( action, fileOrString )

    case( action )
      when XMLTagTreeConstants::OPENFILE then

        # open new file stuff
        if File.exists?(fileOrString)
          file = File.open( fileOrString, "r" )
          @xmlString = file.read
          file.close
        else
          puts "ERROR: File does not exist!!!"
        end

      when XMLTagTreeConstants::USESTRING then

        # load string into class variable
        @xmlString = fileOrString

      else 

        # throw error
        puts "Wrong selection made for XML String Parsing type!!!"

    end

    stripXMLHeader

  end

  def getTagTree

    # </tagName headerData> data </tag tail>
    # </tagName headerData/>
    
    @xmlTree = XMLParser.new( @xmlString )

  end

  def stripXMLHeader

    start = @xmlString.index "<?"
    stop = @xmlString.index "?>\n"

    if start != nil and stop != nil
      @xmlString.slice!(start..(stop + 2))
    end

  end



end
